
package com.e885.util.bean;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DoubleConverter;
import org.apache.commons.beanutils.converters.IntegerConverter;

import com.e885.exception.E885UtilException;

/**
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class BeanUtilImprover
{
	/**
	 * bean copy properties<br>
	 * 目前只有設定下列當來源為 null 時, 目的也會存成 null<br>
	 * 1. Integer<br>
	 * 2. Double<br>
	 * 
	 * @param dest
	 * @param source
	 * @throws E885UtilException
	 */
	public static void copyProperties( Object dest, Object source ) throws E885UtilException
	{
		ConvertUtils.register( new IntegerConverter( null ), Integer.class );
		ConvertUtils.register( new DoubleConverter( null ), Double.class );

		try
		{
			BeanUtils.copyProperties( dest, source );
		}
		catch( IllegalAccessException e )
		{
			e.printStackTrace();

			throw new E885UtilException( e.getMessage() );
		}
		catch( InvocationTargetException e )
		{
			throw new E885UtilException( e.getMessage() );
		}
	}
}
